package com.leaf.u_spring.chapter07;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import com.leaf.u_spring.chapter05.Spittle;

import static org.springframework.web.bind.annotation.RequestMethod.*;

import javax.servlet.http.Part;
import javax.validation.Valid;

/**
 * 文件上传处理
 */
@Controller
public class UploadController {
	
	/**
	 * <form method="POST" enctype="multipart/form-data">
	 * <input type="file" name="profilePicture" accept="image/jpeg,image/png,image/gif"/>
	 * 
	 * @param profilePicture
	 * @param spittle
	 * @return
	 */
	@RequestMapping(value="/uploadImage", method=POST)		
	public String uploadImage(
			@RequestPart("profilePicture") byte[] profilePicture,
			@Valid Spittle spittle){
		
		return null;			
	}	
	
	/**
	 * Spring 提供了更丰富的对象MultipartFile
	 * @param multipartFile
	 * @param spittle
	 * @return
	 */
	@RequestMapping(value="/uploadImage_1", method=POST)		
	public String uploadImage_1(
			MultipartFile multipartFile,
			@Valid Spittle spittle){
		
		return null;			
	}	
	
	/**
	 * Servlet3.0容器提供的 Part
	 * 和MultipartFile类似
	 * @param part
	 * @param spittle
	 * @return
	 */
	@RequestMapping(value="/uploadImage_2", method=POST)		
	public String uploadImage_2(
			Part part,
			@Valid Spittle spittle){
		
		return null;			
	}	
	
}
